\subsection{Motivation and definition}
Recall from IA Analysis that a continuous function on a closed bounded interval is bounded and attains its bounds.
We wish to generalise this result to more general topological spaces.
\begin{example}
	\begin{enumerate}
		\item If \( X \) is finite, any function \( X \to \mathbb R \) is finite.
		\item If, for all continuous functions \( f \colon X \to \mathbb R \) there exists \( n \in \mathbb N \) and subsets \( A_1, \dots, A_n \) of \( X \) such that \( X = \bigcup_{j=1}^n A_j \) and \( f \) is bounded on \( A_j \) for all \( j \), then the property holds.
		\item Note that continuous functions are `locally bounded'; if \( f \colon X \to \mathbb R \) is continuous, then for all \( x \in X \) we have \( U_x = f^{-1}((f(x)-1, f(x)+1)) \) is an open set containing \( X \), and \( f \) is bounded on \( U_x \).
		      So each point has an open neighbourhood on which \( f \) is bounded.
		      Further, \( X = \bigcup_{x \in X} U_x \).
		      If there exists a finite subset \( F \subset X \) such that \( \bigcup_{x \in F} U_x = X \), then \( f \) is bounded on \( X \).
		      This is exactly the definition we will use for compactness.
	\end{enumerate}
\end{example}
\begin{definition}
	Let \( X \) be a topological space.
	An \textit{open cover} for \( X \) is a family \( \mathcal U \) of open subsets of \( X \) that cover \( X \); that is, \( \bigcup_{U \in \mathcal U} U = X \).
	A \textit{subcover} of \( \mathcal U \) is a subset \( \mathcal V \subset \mathcal U \) that covers \( U \).
	This is called a \textit{finite subcover} if \( \mathcal V \) is finite.
	We say that \( X \) is \textit{compact} if every open cover has a finite subcover.
\end{definition}
\begin{remark}
	Compactness can be thought of as the next best thing to finiteness.
\end{remark}
\begin{theorem}
	Let \( X \) be a compact topological space and \( f \colon X \to \mathbb R \) be continuous.
	Then \( f \) is bounded, and if \( X \) is not empty \( f \) attains its bounds.
\end{theorem}
\begin{proof}
	For \( n \in \mathbb N \), let \( U_n = \qty{ x \in X \colon \abs{f(x)} < n} \).
	\( U_n \) is open since \( x \mapsto \abs{f(x)} \) is continuous and \( (-n,n) \) is open.
	It is clear that \( X = \bigcup_{n \in \mathbb N} U_n \).
	This is an open cover of \( X \).
	Hence there exists a finite subcover \( F \subset \mathbb N \) such that \( X = \bigcup_{n \in F} U_n = U_N \) where \( N = \max F \).
	Hence, for all \( x \in X \), we have \( \abs{f(x)} < N \) so \( f \) is bounded.

	Let \( \alpha = \inf_X f \); this exists since \( f \) is bounded.
	Suppose there exists no \( x \in X \) such that \( f(x) = \alpha \).
	Then, for all \( x \in X \), \( f(x) > \alpha \).
	Then there exists \( n \in \mathbb N \) such that \( f(x) > \alpha + \frac{1}{n} \).
	So let
	\[
		V_n = \qty{ x \in X \colon f(x) > \alpha + \frac{1}{n} } = f^{-1}\qty(\qty(\alpha + \frac{1}{n}, \infty))
	\]
	We can see that \( V_n \) is open.
	Now, since \( \bigcup_{n \in \mathbb N} V_n = X \), there exists a finite subcover \( F \subset \mathbb N \) such that \( \bigcup_{n \in F} V_n = X = V_N \) where \( N \) is the maximal \( F \).
	Then for all \( x \in X \), we have \( f(x) > \alpha + \frac{1}{N} \).
	Hence \( \inf_X f \geq \alpha + \frac{1}{N} \), which is a contradiction.
	The same argument applies for the supremum.
\end{proof}
\begin{lemma}
	Let \( Y \) be a subspace of a topological space \( X \).
	Then \( Y \) is compact if and only if whenever \( \mathcal U \) is a family of open sets in \( X \) such that \( \bigcup_{U \in \mathcal U} \supset Y \), there is a finite subfamily \( \mathcal V \subset \mathcal U \) with \( \bigcup_{U \in \mathcal V} U \supset Y \).
\end{lemma}
\begin{theorem}
	\( [0,1] \) is compact.
\end{theorem}
\begin{proof}
	Let \( \mathcal U \) be a family of open sets in \( \mathbb R \) that cover \( [0,1] \).
	For a subset \( A \subset [0,1] \), we say that \( \mathcal U \) \textit{finitely covers} \( A \) if there exists a finite subcover \( \mathcal V \subset \mathcal U \) of \( A \).
	Note that if \( A = B \cup C \) and \( A,B,C \subset [0,1] \) and \( \mathcal U \) finitely covers \( B \) and \( C \), we can take the union of the finite subcovers to find a finite subcover of \( A \), so \( U \) finitely covers \( A \).
	Suppose that \( \mathcal U \) does not finitely cover \( [0,1] \).
	Then one of the intervals \( \qty[0, \frac{1}{2}] \) and \( \qty[\frac{1}{2}, 1] \) is not finitely coverable by \( \mathcal U \).
	Let this interval be \( [a_1, b_1] \).
	Let \( c = \frac{1}{2} (a_1 + b_1) \).
	Then one of the intervals \( [a_1, c], [c,b_1] \) is not finitely coverable by \( \mathcal U \).
	Inductively, we obtain a nested sequence of intervals \( \qty[a_1, b_1] \supset \dots \supset \qty[a_n, b_n] \supset \cdots \) which are not finitely covered by \( \mathcal U \) and \( b_n - a_n = 2^{-n} \).
	Now, \( a_n \to x \) for some \( x \in [0,1] \) and \( b_n = a^n + 2^{-n} \to x \).
	But since \( \mathcal U \) covers \( [0,1] \), there exists \( U \in \mathcal U \) such that \( x \in U \).
	\( U \) is open in \( \mathbb R \), so for all \( \varepsilon > 0 \), we have \( (x-\varepsilon, x+\varepsilon) \subset U \).
	Since \( a_n, b_n \to x \), we can choose \( n \) such that \( a_n, b_n \in (x-\varepsilon, x+\varepsilon) \).
	This is covered by one open set \( U \) in \( \mathcal U \), so this is a finite subcover.
	This is a contradiction.
\end{proof}
\begin{example}
	Other examples of compact spaces include the following.
	\begin{enumerate}
		\item Any finite set is compact.
		\item On any set \( X \), the cofinite topology is compact.
		      Suppose without loss of generality that \( X \) is not empty, and let \( \mathcal U \) be an open cover for \( X \).
		      Let \( U \in \mathcal U \) such that \( U \neq \varnothing \).
		      Then \( F = X \setminus U \) is finite.
		      For all \( x \in F \), let \( U_x \in \mathcal U \) such that \( x \in U_x \).
		      Then \( \bigcup_{x \in F} U_x \cup U \) is a finite subcover.
		\item Let \( x_n \to x \) in a topological space \( X \).
		      Let \( Y = \qty{x_n \colon n \in \mathbb N} \cup \qty{x} \).
		      Then \( Y \) is compact.
		      Indeed, let \( \mathcal U \) be a family of open sets in \( X \) such that \( \bigcup_{U \in \mathcal U} U \supset Y \).
		      In particular, let \( U \in \mathcal U \) such that \( x \in U \).
		      Since \( U \) is open and \( x_n \to x \), there exists \( N \in \mathbb N \) such that for all \( n \geq N \) we have \( x_n \in U \).
		      So we can cover the remaining finitely many elements analogously to the previous example, and this yields a finite subcover.
		\item The indiscrete topology on any set is compact, since there are only two open sets.
	\end{enumerate}
	Counterexamples include the following.
	\begin{enumerate}
		\item An infinite set \( X \) in the discrete topology is not compact.
		      Let
		      \[
			      \mathcal U = \qty{\qty{x} \colon x \in X}
		      \]
		      This has no finite subcover.
		\item \( \mathbb R \) is not compact.
		      Consider the intervals \( (-n, n) \) for all \( n \in \mathbb N \).
		      This is an open cover with no finite subcover.
	\end{enumerate}
\end{example}

\subsection{Subspaces}
\begin{theorem}
	Let \( Y \) be a subspace of a topological space \( X \).
	Then,
	\begin{enumerate}
		\item Let \( X \) be compact and \( Y \) be closed in \( X \).
		      Then \( Y \) is compact.
		\item Let \( X \) be Hausdorff and \( Y \) be compact.
		      Then \( Y \) is closed in \( X \).
	\end{enumerate}
\end{theorem}
\begin{proof}
	Let \( \mathcal U \) be a family of open sets in \( X \) such that their union covers \( Y \).
	Then \( \mathcal U \cup (X \setminus Y) \) is an open cover for \( X \) since \( Y \) is closed.
	This has a finite subcover \( \mathcal V \subset \mathcal U \) such that \( \bigcup_{U \in \mathcal V} U \cup (X \setminus Y) = X \).
	Then \( \bigcup_{U \in \mathcal V} U \supset Y \).

	For part (ii), let \( x \in X \setminus Y \).
	For \( y \in Y \), since \( x \neq y \) there exist open sets \( U_y, V_y \) in \( X \) such that \( x \in U_y, y \in V_y, U_y \cap V_y = \varnothing \).
	Now, \( \qty{V_y \colon y \in Y} \) is an open cover of \( Y \).
	Hence there exists \( F \subset Y \) finite such that \( \bigcup_{y \in F} V_y \supset Y \).
	Now, \( U = \bigcap_{y \in F} U_y \) is open, further \( x \in U \) and
	\[
		U \cap Y \subset \qty(\bigcap_{y \in F} U_y) \cap \qty(\bigcup_{y \in F} V_y) = \varnothing
	\]
	Hence \( X \setminus Y \) is a neighbourhood of all of its points, so it is open and \( Y \) is closed.
\end{proof}

\subsection{Continuous images of compact spaces}
\begin{theorem}
	Let \( f \colon X \to Y \) be a continuous function between topological spaces such that \( X \) is compact.
	Then \( f(X) \) is compact.
\end{theorem}
\begin{proof}
	Let \( \mathcal U \) be a family of open sets in \( Y \) such that \( \bigcup_{U \in \mathcal U} U \supset f(X) \).
	Then \( \bigcup_{U \in \mathcal U} f^{-1}(U) = X \) and \( f^{-1}(U) \) is open in \( X \) for all \( U \in \mathcal U \) since \( f \) is continuous.
	Since \( X \) is compact, we have a finite subcover \( \mathcal V \subset \mathcal U \) such that \( X = \bigcup_{U \in \mathcal V} f^{-1}(V) \).
	Hence \( f(X) \subset \bigcup_{U \in \mathcal V} U \).
\end{proof}
\begin{remark}
	Compactness is a topological property.
	If \( f \colon X \to Y \) is continuous and \( A \subset X \) is compact, then \( f(A) \) is compact.
\end{remark}
\begin{corollary}
	Any quotient of a compact space is compact.
\end{corollary}
\begin{example}
	Let \( a < b \in \mathbb R \).
	Then \( [a,b] \simeq [0,1] \) so is compact.
\end{example}

\subsection{Topological inverse function theorem}
\begin{theorem}
	Let \( f \colon X \to Y \) be a continuous bijection from a compact space \( X \) to a Hausdorff space \( Y \).
	Then \( f^{-1} \) is continuous, so \( f \) is an open map.
	Hence \( f \) is a homeomorphism.
\end{theorem}
\begin{proof}
	Let \( U \) be an open subset of \( X \).
	Then \( K = X \setminus U \) is closed.
	Since \( X \) is compact, \( K \) is compact.
	Further, \( f(K) \) is compact.
	Hence \( f(K) \) is closed in \( Y \).
	So \( f(U) = Y \setminus f(K) \) is open in \( Y \).
\end{proof}
\begin{example}
	\( \mathbb R / \mathbb Z \) is homeomorphic to \( S^1 = \qty{ x \in \mathbb R^2 \colon \norm{x} = 1 } \).
	Indeed, let \( f \colon \mathbb R \to S^1 \) by \( f(t) = (\cos(2\pi t), \sin(2 \pi t)) \).
	For all \( s,t \), we have \( f(s) = f(t) \) if and only if \( s \sim t \) so \( f \) fully respects \( \sim \).
	\( f \) is continuous and surjective.
	Let \( \widetilde f \colon \mathbb R / \mathbb Z \to S^1 \) be the unique map such that \( \widetilde f \circ q = f \).
	So \( \widetilde f \) is a continuous bijection.
	\( S^1 \) is Hausdorff, and \( \mathbb R / \mathbb Z \) is the image of \( [0,1] \) under a continuous map, hence is compact.
	Hence \( \widetilde f \) is a homeomorphism.
\end{example}

\subsection{Tychonov's theorem}
\begin{theorem}
	Let \( X, Y \) be compact topological spaces.
	Then \( X \times Y \) is compact in the product topology.
\end{theorem}
\begin{proof}
	Let \( \mathcal U \) be an open cover for \( X \times Y \).
	We want to show that there exists a finite subcover.
	Without loss of generality, every member of \( \mathcal U \) can be of the form \( U \times V \) where \( U \) is open in \( X \) and \( V \) is open in \( Y \).
	Indeed, for \( z \in X \times Y \) we can choose \( W_z \in \mathcal U \) such that \( z \in W_z \).
	By definition of the product topology, there exist open sets \( U_z \) in \( X \) and \( V_z \) in \( Y \) such that \( z \in U_z \times V_z \subset W_z \).
	So \( \qty{U_z \times V_z \colon z \in X \times Y} \) is an open cover for \( X \times Y \).
	If there exists a finite subset \( F \subset X \times Y \) such that \( \bigcup_{z \in F} U_z \times V_z \) covers \( X \times Y \), then \( \qty{W_x \colon z \in F} \) is a finite subcover of \( \mathcal U \).

	Let \( x \in X \).
	Recall that \( \qty{x} \times Y \) is the continuous image of \( Y \) under the map \( y \mapsto (x,y) \).
	Hence, \( \qty{x} \times Y \) is compact, since the continuous image of a compact space is compact.
	Since \( \qty{x} \times Y \) is covered by \( \bigcup_{W \in \mathcal U} W \), \( \mathcal U \) finitely covers \( \qty{x} \times Y \).
	So there exists \( n_x \in \mathbb N \) such that we can find open sets \( U_{x,1}, \dots, U_{x,n_x} \) in \( X \) and \( V_{x,1}, \dots, V_{x, n_x} \) in \( Y \) such that \( U_{x,j} \times V_{x,j} \in \mathcal U \) and \( \qty{x} \times Y \subset \bigcup_{j=1}^{n_x} U_{x,j} \times V_{x,j} \).

	Without loss of generality, let \( x \in U_{x,j} \) for all \( j \), since any other \( U_{x,j} \) is not needed in the cover.
	Now let \( U_x = \bigcap_{j = 1}^{n_x} U_{x,j} \).
	We know \( x \in U_x \) and \( U_x \) is open since it is a finite intersection of open sets.
	In particular, \( U_x \times Y \subset \bigcup_{j=1}^{n_x} U_{x,j} \times V_{x,j} \).

	Now, \( \qty{U_x \colon x \in X} \) is an open cover for \( X \).
	So there exists a finite subset \( F \subset X \) such that \( X = \bigcup_{x \in F} U_x \).
	Then, \( X \times Y = \bigcup_{x \in F} U_x \times Y \subset \bigcup_{x \in F} \bigcup_{j = 1}^{n_x} U_{x,j} \times V_{x,j} \).
	Hence,
	\[
		\qty{U_{x,j} \times V_{x,j} \colon x \in F, 1 \leq j \leq n_x}
	\]
	is a finite subcover of \( \mathcal U \).
\end{proof}
\begin{remark}
	More generally, if \( X_1, \dots, X_n \) are compact spaces, then so is \( X_1 \times \dots \times X_n \).
\end{remark}

\subsection{Heine--Borel theorem}
\begin{theorem}
	A subset \( K \) of \( \mathbb R^n \) is compact if and only if \( K \) is closed and bounded.
\end{theorem}
\begin{proof}
	Suppose \( K \) is compact.
	\( \mathbb R^n \) is a metric space and hence Hausdorff.
	Hence, \( K \) is closed in \( \mathbb R^n \).
	The function \( x \mapsto \norm{x} \) is continuous.
	Therefore, it is bounded on \( K \).
	So \( K \) is bounded.

	Conversely, if \( K \) is bounded, there exists \( M \geq 0 \) such that for all \( x \in K \) we have \( \norm{x} \leq M \).
	Hence, \( K \subset [-M, M]^n \).
	Note that \( [-M, M] \) is compact since it is homeomorphic to \( [0,1] \).
	By Tychonov's theorem, \( [-M, M]^n \) is compact in the product topology.
	Since a closed subset of a compact space is compact, \( K \) is compact.
\end{proof}
\begin{example}
	Closed balls \( \mathcal B_r(x) \) in \( \mathbb R^n \) are compact.
	The start of the proof for the Lindel\"of--Picard theorem now makes more sense.
\end{example}

\subsection{Sequential compactness}
\begin{definition}
	A topological space \( X \) is \textit{sequentially compact} if every sequence in \( X \) has a convergent subsequence.
	Given a sequence \( (x_n) \) and an infinite set \( M \subset \mathbb N \), we will write \( (x_m)_{m \in M} \) for the subsequence \( (x_{m_n})_{n=1}^\infty \) where \( m_1 < m_2 < \dots \) are the elements of \( M \).
	Note that if \( L \subset M \subset \mathbb N \), then \( (x_n)_{n \in L} \) is a subsequence of \( (x_n)_{n \in M} \).
\end{definition}
\begin{example}
	Any closed and bounded subset of \( \mathbb R \) is sequentially compact by the Bolzano--Weierstrass theorem.
	Similarly, any closed and bounded subset \( K \) of \( \mathbb R^n \) is sequentially compact.
	Indeed, let \( (x_m) \) be a sequence in \( K \).
	Then, writing \( x_m = (x_{m,1}, \dots, x_{m,n}) \), since \( K \) is bounded we have that \( (x_{m,j}) \) is bounded for all \( j \).
	Applying the Bolzano--Weierstrass theorem to the first coordinate, we find \( M_1 \subset \mathbb N \) such that \( (x_{m,1})_{m \in M_1} \) converges in \( \mathbb R \).
	Now, \( (x_{m,2})_{m \in M_1} \) is bounded in \( \mathbb R \), so again applying the Bolzano--Weierstrass theorem, we can find \( M_2 \subset \mathbb N \) such that \( (x_{m,2})_{m \in M_2} \) converges.
	Note that \( (x_{m,1})_{m \in M_2} \) converges.
	So inductively we can find \( M_1 \supset \dots \supset M_n \) such that \( (x_{m,j})_{m \in M_n} \) converges for all \( j \).
	Hence \( (x_m)_{m \in M_n} \) converges in \( \mathbb R^n \).
	The limit is contained in \( K \) since \( K \) is closed.
\end{example}
\begin{remark}
	In \( \mathbb R^n \), any compact space is sequenctially compact.
	The converse is also true; any sequentially compact subspace must be closed and bounded.
	We aim to show that compactness and sequential compactness are identical in metric spaces.
\end{remark}

\subsection{Compactness and sequential compactness in metric spaces}
Let \( (M, d) \) be a metric space.
\begin{definition}
	For \( \varepsilon > 0 \) and \( F \subset M \), we say that \( F \) is an \textit{\( \varepsilon \)-net for \( M \)} if for all \( x \in M \), there exists \( y \in F \) such that \( d(y,x) \leq \varepsilon \).
	Equivalently, \( M = \bigcup_{y \in M} \mathcal B_\varepsilon(y) \).
	This is called a \textit{finite \( \varepsilon \)-net} if \( F \) is finite.
	We say that \( M \) is \textit{totally bounded} if for all \( \varepsilon > 0 \), there exists a finite \( \varepsilon \)-net for \( M \).
\end{definition}
\begin{example}
	For \( \varepsilon > 0 \), let \( n \) such that \( \frac{1}{n} < \varepsilon \).
	Then \( \qty{\frac{1}{n}, \frac{2}{n}, \dots, \frac{n-1}{n}} \) is an \( \varepsilon \)-net for \( (0,1) \).
\end{example}
\begin{definition}
	For a non-empty \( A \subset M \), the \textit{diameter} of \( A \) is \( \diam A = \sup\qty{d(x,y) \colon x,y \in A} \).
	This is finite if and only if \( A \) is a bounded set.
\end{definition}
\begin{example}
	\( \diam \mathcal B_r(x) \leq 2r \).
\end{example}
\begin{lemma}
	Suppose \( M \) is totally bounded.
	Let \( A \) be a non-empty closed subset of \( M \).
	Let \( \varepsilon > 0 \).
	Then there exists \( K \in \mathbb N \) and non-empty closed sets \( B_1, \dots, B_K \) such that \( A = \bigcup_{k=1}^K B_k \) and \( \diam B_k \leq \varepsilon \) for all \( k \).
\end{lemma}
\begin{proof}
	Let \( F \) be a finite \( \frac{\varepsilon}{2} \)-net for \( M \).
	So \( M = \bigcup_{x \in F} B_{\varepsilon/2}(x) \) and hence \( A = \bigcup_{x \in F} (A \cap B_{\varepsilon/2}(x)) \).
	Let \( G = \qty{ x \in F \colon A \cap B_{\varepsilon / 2}(x) \neq 0 } \).
	Then for \( x \in G \) let \( B_x = A \cap B_{\varepsilon / 2}(x) \).
	So for \( x \in G \), we have \( B_x \neq \varnothing \), \( B_x \subset B_{\varepsilon/2}(x) \) and so \( \diam B_x \leq \varepsilon \), and \( B_x \) is closed.
	Then \( A = \bigcup_{x \in G} B_x \).
\end{proof}
\begin{theorem}
	For a metric space \( (M, d) \), the following are equivalent.
	\begin{enumerate}
		\item \( M \) is compact;
		\item \( M \) is sequentially compact;
		\item \( M \) is complete and totally bounded.
	\end{enumerate}
\end{theorem}
\begin{proof}
	We first show (i) implies (ii).
	Let \( (x_n) \) be a sequence in \( M \).
	Then for \( n \in \mathbb N \), let \( T_n = \qty{x_k \colon k > n} \) be the tail of the sequence.
	Note that the limit of any convergent subsequence (if it exists) is in the intersection of \( \bigcap_{n \in \mathbb N} \overline T_n \).
	So first, we prove that this intersection is non-empty.
	Suppose that it is empty.
	Then, \( \bigcup_{n \in \mathbb N} \qty(M \setminus \overline T_n) = M \).
	But the \( M \setminus \overline T_n \) are open, and \( M \) is compact, there is a finite subcover.
	So \( M \setminus \overline T_N = M \) for some \( N \), since the \( T_n \) are a decreasing sequence of sets.
	This is a contradiction since \( T_N \neq \varnothing \).
	Now, let \( x \in \bigcap_{n \in \mathbb N} \overline T_n \), and we want to show the existence of a subsequence converging to \( x \).
	First, \( x \in \overline T_1 \), so \( \mathcal D_1(x) \cap T_1 \neq \varnothing \).
	Hence there exists \( k_1 > 1 \) such that \( d(x_{k_1}, x) < 1 \).
	Now since \( x \in \overline T_{k_1} \), \( \mathcal D_{1/2}(x) \cap T_{k_1} \neq \varnothing \).
	There exists \( k_2 > k_1 \) such that \( d(x_{k_2}, x) < \frac{1}{2} \).
	Inductively, we can find a strictly increasing sequence \( k_1 < k_2 < \dots \) such that \( d(x_{k_n}, x) < \frac{1}{n} \) for all \( n \), so \( x_{k_n} \to x \).

	Now, we show (ii) implies (iii).
	To show \( M \) is complete, let \( (x_n) \) be a Cauchy sequence in \( M \).
	Let \( k_1 < k_2 < \dots \) such that \( x_{k_n} \) converges in \( M \), and let \( x \) be the limit.
	We show \( x_n \to x \).
	Indeed, for \( \varepsilon > 0 \), there exists \( N \in \mathbb N \) such that \( \forall m, n \geq N \), we have \( d(x_m, x_n) < \varepsilon \).
	Then \( \forall m \geq N \), we have \( k_n \geq m \geq N \), so for a fixed \( n \geq N \) and \( \forall m \geq N \), we have \( d(x_n, x) \leq d(x_n, x_{k_m}) + d(x_{k_m}, x) \leq \varepsilon + d(x_{k_m}, x) \).
	Let \( m \to \infty \), so \( d(x_n, x) \leq \varepsilon \).
	So \( x_n \to x \).
	To show \( M \) is totally bounded, suppose it is not.
	There exists \( \varepsilon > 0 \) such that \( M \) has no finite \( \varepsilon \)-net.
	Let \( x_1 \in M \), and suppose we can find \( x_1, \dots, x_{n-1} \) in \( M \).
	Then \( \bigcup_{j=1}^{n-1} \mathcal B_\varepsilon(x_j) \neq M \).
	So we can pick \( x_n \in M \setminus \bigcup_{j-1}^{n-1} \mathcal B_\varepsilon(x_j) \).
	Inductively we obtain \( (x_n) \) such that \( d(x_m, x_n) > \varepsilon \) for all \( n, m \in \mathbb N \).
	So \( (x_n) \) has no Cauchy subsequence.
	There is therefore no convergent subsequence, which is a contradiction.

	Finally, we show (iii) implies (i).
	Let \( \mathcal U \) be an open cover for \( M \).
	We must show there exists a finite subcover.
	Suppose that is not true, so \( \mathcal U \) does not finitely cover \( M \).
	We construct non-empty closed subsets \( A_0 \supset A_1 \supset \dots \) of \( M \) such that for all \( n \geq 0 \), \( \mathcal U \) does not finitely cover \( A_n \), and for all \( n \geq 1 \) we have \( \diam A_n < \frac{1}{n} \).
	Let \( A_0 = M \).
	Suppose that for some \( n \geq 1 \) we have already found \( A_{n-1} \).
	Since \( M \) is totally bounded, we can write \( A_{n-1} = \bigcup_{k=1}^K B_k \) where \( K \in \mathbb N \) and the \( B_k \) are non-empty, closed, and \( \diam B_k < \frac{1}{n} \).
	Since \( \mathcal U \) does not finitely cover \( A_{n-1} \), there exists \( k \leq K \) such that \( \mathcal U \) does not finitely cover \( B_k \).
	Let \( A_n \) be this \( B_k \).
	Now, for all \( n \), pick some \( x_n \in A_n \).
	For all \( N \), \( \forall m,n \geq N \) we have \( x_m, x_n \in A_N \) hence \( d(x_m, x_n) \leq \diam A_N \leq \frac{1}{n} \) so the sequence is Cauchy.
	\( M \) is complete, so \( x_n \to x \) for some \( x \in M \).
	Let \( U \in \mathcal U \) such that \( x \in U \).
	\( U \) is open, so there exists \( r > 0 \) such that \( \mathcal D_r(x) \subset U \).
	But \( x_n \to x \) hence there exists \( n \) such that \( d(x_n, x) < \frac{r}{2} \) and \( \diam A_n < \frac{r}{2} \).
	For every \( y \in A_n \), \( d(y,x) \leq d(y,x_n) + d(x_n, x) \leq \diam A_n + \frac{r}{2} < r \).
	Hence every point in \( A_n \) is contained within \( \mathcal D_r(x) \subset U \).
	But this contradicts the fact that \( \mathcal U \) does not finitely cover \( A_n \), but we have constructed a cover using just one open set.
\end{proof}
\begin{remark}
	We can now deduce the one direction of the Heine--Borel theorem from the Bolzano--Weierstrass theorem; closed and bounded subsets of \( \mathbb R^n \) are compact.
	Similarly, we can check that the product of sequentially compact topological spaces is sequentially compact in the product topology.
	This yields a new proof for Tychonov's theorem for metric spaces.
	In general, there exist topological spaces that are compact but not sequentially compact, and conversely there exist topological spaces which are sequentially compact but not compact.
\end{remark}
